ThisBuild / version := "1.0"

ThisBuild / scalaVersion := "2.13.8"

val nameStr = "gep_liver"
name := nameStr
lazy val commonSettings = Seq(
  scalaVersion := "2.13.8"
)
lazy val shared = crossProject(JSPlatform, JVMPlatform)
  .crossType(CrossType.Pure)
  .in(file("shared"))
  .settings(commonSettings)
  .settings(
    scalacOptions ++= {
      Seq("-Ymacro-annotations")
    },
    libraryDependencies ++= Seq(
      "com.lihaoyi" %% "upickle" % "2.0.0"
    )
  )

lazy val sharedJvm = shared.jvm
lazy val sharedJs = shared.js

lazy val server = (project in file("server"))
  .settings(
    name := s"${nameStr}_server",
    fork := true,
    Test / fork := true, // allows for graceful shutdown of containers once the tests have finished running
    libraryDependencies ++= Seq(
      guice,
      specs2 % Test,
      ws,
      ehcache,
      "com.typesafe.play" %% "play-slick" % "4.0.2",
      "com.typesafe.slick" %% "slick-codegen" % "3.3.2",
      "mysql" % "mysql-connector-java" % "5.1.25",
      "com.github.tototoshi" %% "slick-joda-mapper" % "2.4.1",
      "commons-io" % "commons-io" % "2.5",
      "org.apache.poi" % "poi-ooxml" % "3.15",
      "org.apache.commons" % "commons-math3" % "3.6.1",
      "com.aliyun" % "aliyun-java-sdk-core" % "3.7.1",
      "com.aliyun" % "aliyun-java-sdk-dysmsapi" % "1.1.0",
      "com.typesafe.play" %% "play-joda-forms" % "2.7.3",
      "org.apache.xmlgraphics" % "batik-codec" % "1.10",
      "org.zeroturnaround" % "zt-zip" % "1.11",
      "com.github.tototoshi" %% "scala-csv" % "1.3.6",
      "junit" % "junit" % "4.12" % Test,
      "org.apache.pdfbox" % "pdfbox" % "2.0.8",
      "org.apache.pdfbox" % "pdfbox-tools" % "2.0.8",
      "com.h2database" % "h2" % "1.4.199",
      "javax.xml.bind" % "jaxb-api" % "2.3.0",
      "org.apache.commons" % "commons-lang3" % "3.6",
      "org.scala-lang.modules" %% "scala-parallel-collections" % "0.2.0",
      "org.typelevel" %% "cats-core" % "2.0.0",
      "javax.mail" % "mail" % "1.4.7",
      "org.scala-lang" % "scala-reflect" % "2.13.1",
      "org.postgresql" % "postgresql" % "42.2.5",
      "com.github.tminglei" %% "slick-pg" % "0.19.0",
      "com.github.tminglei" %% "slick-pg_joda-time" % "0.19.0",
      "com.github.tminglei" %% "slick-pg_play-json" % "0.19.0",
      "com.github.tminglei" %% "slick-pg_jts" % "0.19.0",
      "com.github.julien-truffaut" %% "monocle-core" % "2.0.3",
      "com.github.julien-truffaut" %% "monocle-macro" % "2.0.3",
      "org.scalatestplus.play" %% "scalatestplus-play" % "5.1.0" % Test,
      "org.scala-graph" %% "graph-core" % "1.13.2",
      "io.scalaland" %% "chimney" % "0.5.3",
      "com.itextpdf" % "itext-asian" % "5.2.0",
      "com.softwaremill.quicklens" %% "quicklens" % "1.6.1",
      "org.biojava" % "biojava-core" % "5.0.0",
      "com.lihaoyi" %% "os-lib" % "0.7.8",
      "com.google.zxing" % "core" % "3.4.1",
      "com.google.zxing" % "javase" % "3.4.1",
      "com.github.jwt-scala" %% "jwt-core" % "9.0.5",
      "de.svenkubiak" % "jBCrypt" % "0.4.3",
      "com.lihaoyi" %% "upickle" % "2.0.0",
      "com.lihaoyi" %% "ujson-play" % "2.0.0"
    ),
    scalacOptions ++= {
      Seq(
        "-Ymacro-annotations"
      )
    }
  ).enablePlugins(PlayScala).disablePlugins(PlayLayoutPlugin).dependsOn(sharedJvm)

val reactVersion = "17.0.2"

lazy val client = (project in file("client"))
  .settings(
    name := "client",
    useYarn := true,
    webpackDevServerPort := 8080,
    webpack / version := "4.40.2",
    startWebpackDevServer / version := "3.11.2",
    webpackResources := baseDirectory.value / "webpack" * "*",
    fastOptJS / webpackConfigFile := Some(baseDirectory.value / "webpack" / "webpack-fastopt.config.js"),
    fullOptJS / webpackConfigFile := Some(baseDirectory.value / "webpack" / "webpack-opt.config.js"),
    fullOptJS / webpackEmitSourceMaps := false,
    Test / webpackConfigFile := Some(baseDirectory.value / "webpack" / "webpack-core.config.js"),
    fastOptJS / webpackDevServerExtraArgs := Seq("--inline", "--hot"),
    fastOptJS / webpackBundlingMode := BundlingMode.LibraryOnly(),
    fastOptJS / webpackEmitSourceMaps := false,
    Compile / npmDependencies ++= Seq(
      "jquery" -> "3.5.0",
      "react" -> reactVersion,
      "react-dom" -> reactVersion,
      "react-proxy" -> "1.1.8",
      "file-loader" -> "6.2.0",
      "style-loader" -> "2.0.0",
      "css-loader" -> "5.2.6",
      "html-webpack-plugin" -> "4.5.1",
      "copy-webpack-plugin" -> "6.4.0",
      "webpack-merge" -> "5.8.0",
      "react-router-dom" -> "6.2.1",
      "react-i18next" -> "11.16.2",
      "i18next" -> "21.6.14",
      "bootstrap-datepicker" -> "1.6.4",
      "react-bootstrap" -> "1.6.4",
      "bootstrap-sweetalert" -> "1.0.1",
      "layer-src" -> "3.5.1",
      "bootstrapvalidator" -> "0.5.4",
      "nprogress" -> "0.2.0",
      "react-transition-group" -> "4.4.2",
      "dom-helpers" -> "5.2.1",
      "bootstrap" -> "4.6.1",
      "qrcode" -> "1.5.0",
      "jszip" -> "3.7.1",
      "react-image-lightbox" -> "5.1.4",
      "select2" -> "4.0.13",
      "plotly.js-basic-dist-min" -> "2.11.1",
      "bootstrap-multiselect" -> "1.1.0",
      "knockout" -> "3.5.1",
      "@fortawesome/fontawesome-free" -> "5.15.1",
      "highcharts" -> "10.1.0",
      "bootstrap-3-typeahead" -> "4.0.2",
      "@types/react" -> reactVersion
    ),
    libraryDependencies ++= Seq(
      "me.shadaj" %%% "slinky-web" % "0.7.2",
      "me.shadaj" %%% "slinky-hot" % "0.7.2",
      "com.lihaoyi" %%% "scalatags" % "0.11.1",
      "com.softwaremill.quicklens" %%% "quicklens" % "1.6.1",
      "org.scala-js" %%% "scala-js-macrotask-executor" % "1.0.0",
      "com.lihaoyi" %%% "upickle" % "2.0.0",
      "io.scalaland" %%% "chimney" % "0.6.1"
    ),
    scalacOptions ++= {
      Seq(
        "-Ymacro-annotations"
      )
    },
    stFlavour := Flavour.Slinky,
    stIgnore := List(
      "jquery",
      "react-dom",
      "react-proxy",
      "file-loader",
      "style-loader",
      "css-loader",
      "html-webpack-plugin",
      "copy-webpack-plugin",
      "webpack-merge",
      "react-router-dom",
      "react-i18next",
      "i18next",
      "bootstrap-datepicker",
      "react-bootstrap",
      "bootstrap-sweetalert",
      "layer-src",
      "bootstrapvalidator",
      "nprogress",
      "react-transition-group",
      "dom-helpers",
      "bootstrap",
      "qrcode",
      "jszip",
      "react-image-lightbox",
      "select2",
      "plotly.js-basic-dist-min",
      "bootstrap-multiselect",
      "knockout",
      "@fortawesome/fontawesome-free",
      "highcharts",
      "bootstrap-3-typeahead"
    )
  ).enablePlugins(ScalaJSBundlerPlugin, ScalablyTypedConverterPlugin).dependsOn(sharedJs)

addCommandAlias("dev", ";client/fastOptJS::startWebpackDevServer;~client/fastOptJS")
addCommandAlias("stop-dev", ";client/fastOptJS::stopWebpackDevServer")
addCommandAlias("build", "client/fullOptJS::webpack")
